package jobs.project_byte_summary;

import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class ProjectByteSummariserReduce extends Reducer<Text, LongWritable, Text, LongWritable> {
	public void reduce(Text key, Iterable<LongWritable> values, Context context)	throws IOException, InterruptedException {
		
		//System.out.println("Running Reducer for key: " + key);
		
		Iterator<LongWritable> intValues = values.iterator();
		long sum = 0;
		while (intValues.hasNext()) {
			sum += intValues.next().get();
		}
		
		//System.out.println("Finished Reducer. Writing result for key: " + key + " as " + sum);
		context.write(key, new LongWritable(sum));
	}
}
